﻿Imports System.Configuration
Imports System.Net.Configuration
Imports System.Web.Configuration

Public Class Sys
    Private Shared _dbConnectionString As String
    Public Shared ReadOnly Property DbConnectionString As String
        Get
            If _dbConnectionString Is Nothing Then
                _dbConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings(Constants.Connections.EQUIPMENT_CONNECTION_STRING).ConnectionString
            End If
            Return _dbConnectionString
        End Get
    End Property

    Private Shared _smtpServer As String
    Public Shared ReadOnly Property SmtpServer As String
        Get
            If _smtpServer Is Nothing Then
                _smtpServer = SMTPSettings.Network.Host
            End If
            Return _smtpServer
        End Get
    End Property

    Private Shared _smtpPort As String
    Public Shared ReadOnly Property SmtpPort As String
        Get
            If _smtpPort Is Nothing Then
                _smtpPort = SMTPSettings.Network.Port
            End If
            Return _smtpPort
        End Get
    End Property

    Private Shared _supportEmail As String
    Public Shared ReadOnly Property SupportEmail As String
        Get
            If _supportEmail Is Nothing Then
                _supportEmail = System.Configuration.ConfigurationManager.AppSettings(Constants.Mail.SUPPORT_EMAIL)
            End If
            Return _supportEmail
        End Get
    End Property

    Private Shared _smtpSettings As SmtpSection
    Public Shared ReadOnly Property SMTPSettings As SmtpSection
        Get
            If _smtpSettings Is Nothing Then
                _smtpSettings = ConfigurationManager.GetSection(Constants.Mail.SMTP_SETTINGS)
            End If
            Return _smtpSettings
        End Get
    End Property

    Private Shared _bRequiredAuthenticationForWorkOrder As Boolean
    Public Shared Property RequiredAuthenticationForWorkOrder As Boolean
        Set(ByVal value As Boolean)
            _bRequiredAuthenticationForWorkOrder = value

            Dim config As System.Configuration.Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
            config.AppSettings.Settings(Constants.Authentication.REQUIRED_AUTHENTICATION_FOR_WORK_ORDER).Value = value.ToString()
            config.AppSettings.SectionInformation.RestartOnExternalChanges = False
            config.Save(ConfigurationSaveMode.Modified)
            ConfigurationManager.RefreshSection("appSettings")
        End Set
        Get
            _bRequiredAuthenticationForWorkOrder = ConfigurationManager.AppSettings(Constants.Authentication.REQUIRED_AUTHENTICATION_FOR_WORK_ORDER)
            Return _bRequiredAuthenticationForWorkOrder
        End Get
    End Property

    Private Shared _iRequestPasswordChange As Integer
    Public Shared Property RequestPasswordChange As Integer
        Set(ByVal value As Integer)
            _iRequestPasswordChange = value
            Dim config As System.Configuration.Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
            config.AppSettings.Settings(Constants.Authentication.REQUEST_PASSWORD_CHANGE).Value = value.ToString()
            config.AppSettings.SectionInformation.RestartOnExternalChanges = False
            config.Save(ConfigurationSaveMode.Modified)
            ConfigurationManager.RefreshSection("appSettings")
        End Set
        Get
            _iRequestPasswordChange = ConfigurationManager.AppSettings(Constants.Authentication.REQUEST_PASSWORD_CHANGE)
            Return _iRequestPasswordChange
        End Get
    End Property
End Class
